<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="postgres," />





  <link rel="alternate" href="/atom.xml" title="搁浅丶岁月的变迁" type="application/atom+xml" />






<meta name="description" content="1.字符串转换#字符串转时间 CONVERT(DATETIME, &amp;apos;&amp;apos;1900-01-01 00:00:00&amp;apos;&amp;apos;, 102) to_timestamp(&amp;apos;1900-01-01 00:00:00.000&amp;apos;,&amp;apos;YYYY-mm-dd HH24:MI:SS.MS&amp;apos;)  #时间转字符串 convert(varchar(10),g">
<meta name="keywords" content="postgres">
<meta property="og:type" content="article">
<meta property="og:title" content="postgres sqlserver常用函数对比">
<meta property="og:url" content="http://yoursite.com/2018/02/07/2018-02-07-postgres sqlserver常用函数对比/index.html">
<meta property="og:site_name" content="搁浅丶岁月的变迁">
<meta property="og:description" content="1.字符串转换#字符串转时间 CONVERT(DATETIME, &amp;apos;&amp;apos;1900-01-01 00:00:00&amp;apos;&amp;apos;, 102) to_timestamp(&amp;apos;1900-01-01 00:00:00.000&amp;apos;,&amp;apos;YYYY-mm-dd HH24:MI:SS.MS&amp;apos;)  #时间转字符串 convert(varchar(10),g">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-05-31T04:53:01.292Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="postgres sqlserver常用函数对比">
<meta name="twitter:description" content="1.字符串转换#字符串转时间 CONVERT(DATETIME, &amp;apos;&amp;apos;1900-01-01 00:00:00&amp;apos;&amp;apos;, 102) to_timestamp(&amp;apos;1900-01-01 00:00:00.000&amp;apos;,&amp;apos;YYYY-mm-dd HH24:MI:SS.MS&amp;apos;)  #时间转字符串 convert(varchar(10),g">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/02/07/2018-02-07-postgres sqlserver常用函数对比/"/>





  <title>postgres sqlserver常用函数对比 | 搁浅丶岁月的变迁</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <a href="https://github.com/liaoren512"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub"></a>
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">搁浅丶岁月的变迁</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">没有虽败犹荣，只有成王败寇。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/02/07/2018-02-07-postgres sqlserver常用函数对比/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="廖壬">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/ichgo.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="搁浅丶岁月的变迁">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">postgres sqlserver常用函数对比</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-02-07T00:00:00+08:00">
                2018-02-07
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SQL/" itemprop="url" rel="index">
                    <span itemprop="name">SQL</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="1-字符串转换"><a href="#1-字符串转换" class="headerlink" title="1.字符串转换"></a>1.字符串转换</h3><pre><code>#字符串转时间
CONVERT(DATETIME, &apos;&apos;1900-01-01 00:00:00&apos;&apos;, 102)
to_timestamp(&apos;1900-01-01 00:00:00.000&apos;,&apos;YYYY-mm-dd HH24:MI:SS.MS&apos;)

#时间转字符串
convert(varchar(10),getdate(),120)
to_char(current_timestamp, &apos;yyyy-mm-dd HH24:MI:SS.MS&apos;);

#字符串转数字
convert(int,&apos;3&apos;)
to_number(string,&apos;9&apos;)

#数字转字符串
convert(varchar(5),3)
to_char(ReasonNo, &apos;9999999999&apos;)
</code></pre><h3 id="2-分割字符串"><a href="#2-分割字符串" class="headerlink" title="2.分割字符串"></a>2.分割字符串</h3><pre><code>#取右侧字符串
RIGHT(@BranchCD_1,4)
substring(BranchCD_1 from &apos;....$&apos;);1个.代表一位

#去空格
trim(strSQL)
btrim(strSQL, &apos; &apos;)
</code></pre><h3 id="3-大小写转换"><a href="#3-大小写转换" class="headerlink" title="3.大小写转换"></a>3.大小写转换</h3><pre><code>lower(&apos;STRSQL&apos;);
lower(&apos;STRSQL&apos;);
</code></pre><h3 id="4-替换null"><a href="#4-替换null" class="headerlink" title="4.替换null"></a>4.替换null</h3><pre><code>isnull(RetailStock,0)
COALESCE(RetailStock,0)
</code></pre><h3 id="5-执行字符串"><a href="#5-执行字符串" class="headerlink" title="5.执行字符串"></a>5.执行字符串</h3><pre><code>exec strSQL
execute strSQL
</code></pre><h3 id="6-拼接字符串"><a href="#6-拼接字符串" class="headerlink" title="6.拼接字符串"></a>6.拼接字符串</h3><pre><code>aaaa&apos; + &apos;ccccc&apos; + &apos;bbb&apos;
aaaa&apos; || &apos;ccccc&apos; || &apos;bbb&apos;
</code></pre><h3 id="7-拼接字符串插入变量"><a href="#7-拼接字符串插入变量" class="headerlink" title="7.拼接字符串插入变量"></a>7.拼接字符串插入变量</h3><pre><code>&quot;EXEC &apos;select @v_upInt = name
from &apos; + @v_str_StockTable + &apos;;&apos;;&quot;

&quot;v_strSQL_UpdatePack_EXITS :=&apos;select 1 from &apos; || v_str_StockTable || &apos;;&apos;;
EXECUTE v_strSQL_UpdatePack_EXITS into v_upInt;&quot;
</code></pre><h3 id="8-取前-n-行"><a href="#8-取前-n-行" class="headerlink" title="8.取前 n  行"></a>8.取前 n  行</h3><pre><code>select top 1 * from table
select * from table limit 1
</code></pre><h3 id="9-新建临时表"><a href="#9-新建临时表" class="headerlink" title="9.新建临时表"></a>9.新建临时表</h3><pre><code> Create table #TempStocksAdjust
(
    SingleProductCode varchar(15) NOT NULL
);


Create temp table TempStocksAdjust
(
    SingleProductCode varchar(15) NOT NULL
);
</code></pre><h3 id="10-if"><a href="#10-if" class="headerlink" title="10.if"></a>10.if</h3><pre><code>if exists (select 1 from str_StockTable where ProductCode = &apos;&apos;ProdCode&apos;&apos;)
begin
    select 1
end

if  exists( select *from information_schema.tables where table_name = v_tablename)
then
    execute v_sql1;
end if;
</code></pre><h3 id="11-while"><a href="#11-while" class="headerlink" title="11.while"></a>11.while</h3><pre><code>WHILE (SELECT AVG(ListPrice) FROM Production.Product) &lt; $300
BEGIN
   select 1
END

while v_i&lt;320 loop
    select 1
end loop;
</code></pre><h3 id="12-for"><a href="#12-for" class="headerlink" title="12.for"></a>12.for</h3><pre><code>null

FOR i IN 1..10 LOOP
    select 1;
END LOOP;
</code></pre><h3 id="13-向变量赋值"><a href="#13-向变量赋值" class="headerlink" title="13.向变量赋值"></a>13.向变量赋值</h3><pre><code>SELECT @PackIrisu = BundleQty
FROM TmpProduct ;

SELECT BundleQty INTO  v_PackIrisu
FROM TmpProduct ;
</code></pre><h3 id="14-从某表新建表并插入数据"><a href="#14-从某表新建表并插入数据" class="headerlink" title="14.从某表新建表并插入数据"></a>14.从某表新建表并插入数据</h3><pre><code>SELECT
    T.ProductCode   AS  ProductCode
INTO HistoryTempA1
FROM TempTable_StocksAdjust T

CREATE TABLE HistoryTempA1 AS
SELECT T.ProductCode AS ProductCode
FROM TempTable_StocksAdjust T;
</code></pre><h3 id="15-赋值"><a href="#15-赋值" class="headerlink" title="15.赋值"></a>15.赋值</h3><pre><code>strSQL=&apos;aaaa&apos;
strSQL:=&apos;aaaa&apos;
</code></pre><h3 id="16-获取传入参数"><a href="#16-获取传入参数" class="headerlink" title="16.获取传入参数"></a>16.获取传入参数</h3><pre><code>EXEC  GetNewUpdateID @ReturnID = @StockUpdateId OUTPUT
select v_returnid INTO v_StockUpdateId from stockdb.GetNewUpdateID();
</code></pre><h3 id="17-执行存储过程"><a href="#17-执行存储过程" class="headerlink" title="17.执行存储过程"></a>17.执行存储过程</h3><pre><code>exec GetNewUpdateID
SELECT * from stockdb.getnewupdateid();
</code></pre><h3 id="18-定义变量"><a href="#18-定义变量" class="headerlink" title="18.定义变量"></a>18.定义变量</h3><pre><code>DECLARE @strSQL_Delete AS VARCHAR(1000)
DECLARE v_str_StockTable varchar(50);
</code></pre><h3 id="19-打印语句"><a href="#19-打印语句" class="headerlink" title="19.打印语句"></a>19.打印语句</h3><pre><code>PRINT @ExecuteSQL
RAISE NOTICE &apos;%&apos; , v_sql;
</code></pre><h3 id="20-捕获异常"><a href="#20-捕获异常" class="headerlink" title="20.捕获异常"></a>20.捕获异常</h3><pre><code>IF(@@ERROR&lt;&gt;0)
Begin
    Select @LogMsg=@strStoreCd+&apos;店入荷予定日更新失敗。&apos;
    Goto Error_Handle
End

BEGIN
    execute v_sq into v_count;
    EXCEPTION WHEN OTHERS THEN
    RAISE NOTICE &apos;%&apos; , SQLERRM;
END;
</code></pre><h3 id="21-查找字符串所在位置"><a href="#21-查找字符串所在位置" class="headerlink" title="21.查找字符串所在位置"></a>21.查找字符串所在位置</h3><pre><code>CHARINDEX(&apos;/-/&apos;,@ORDER_NUM_STR)
POSITION(&apos;/-/&apos; in v_ORDER_NUM_STR);
</code></pre><h3 id="22-delete-join"><a href="#22-delete-join" class="headerlink" title="22.delete join"></a>22.delete join</h3><pre><code>Delete #T_Wスケジュール
From #T_Wスケジュール T1
Inner Join T_D例外スケジュール T2
On T1.BranchCD=T2.店CD
And T1.SupplierCD=T2.ベンダーCD
And T1.DeliveryWeekDay=T2.納品曜日
Where  T1.[WeekDay]&lt;&gt;T2.発注曜日

delete from T_Wスケジュール T1
where exists
(   select *
    From T_D例外スケジュール T2
    Where T1.BranchCD=T2.店CD
        And T1.SupplierCD=T2.ベンダーCD
        And T1.DeliveryWeekDay=T2.納品曜日
        and  T1.WeekDay&lt;&gt;T2.発注曜日
);
</code></pre><h3 id="23-update-join"><a href="#23-update-join" class="headerlink" title="23.update join"></a>23.update join</h3><pre><code>UPDATE T1
set T1.OrderDateTime =  T2.発注日
from shT_Temp_ConfineTable_in_IP as T1
inner join T_W修正発注締切日 as  T2
on  T2.ベンダーCD=T1.SupplierCD

UPDATE shT_Temp_ConfineTable_in_IP  T1
set OrderDateTime =  T2.発注日
from T_W修正発注締切日 T2
WHERE T2.ベンダーCD=T1.SupplierCD
</code></pre><h3 id="24-时间-日期的加减"><a href="#24-时间-日期的加减" class="headerlink" title="24.时间,日期的加减"></a>24.时间,日期的加减</h3><pre><code>dateadd(day,2,getdate())
date &apos;2001-09-28&apos; + interval &apos;1 hour&apos;
</code></pre><h3 id="25-获取日期时间中的一段"><a href="#25-获取日期时间中的一段" class="headerlink" title="25.获取日期时间中的一段"></a>25.获取日期时间中的一段</h3><pre><code>select DatePart (yyyy ,getdate())
EXTRACT(DAY from now())
</code></pre><h3 id="26-返回当前系统日期时间"><a href="#26-返回当前系统日期时间" class="headerlink" title="26.返回当前系统日期时间"></a>26.返回当前系统日期时间</h3><pre><code>select getdate()
select now();
</code></pre>
      
    </div>
    
    
    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      
    </div>

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <!--<a href="/tags/postgres/" rel="tag"># postgres</a>-->
            <a href="/tags/postgres/" rel="tag"><i class="fa fa-tag"></i> postgres</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/02/07/2018-02-07-centos6.5 安装nfs/" rel="next" title="centos6.5 安装nfs">
                <i class="fa fa-chevron-left"></i> centos6.5 安装nfs
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/02/07/2018-02-07-postgres sqlserver数据类型对比/" rel="prev" title="postgres sqlserver数据类型对比">
                postgres sqlserver数据类型对比 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到：</span>
<a class="jiathis_button_fav">收藏夹</a>
<a class="jiathis_button_copy">复制网址</a>
<a class="jiathis_button_email">邮件</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_qzone">QQ空间</a>
<a class="jiathis_button_tqq">腾讯微博</a>
<a class="jiathis_button_douban">豆瓣</a>
<a class="jiathis_button_share">一键分享</a>

<a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
var jiathis_config={
  data_track_clickback:true,
  summary:"",
  shortUrl:false,
  hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script>
<!-- JiaThis Button END -->
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/ichgo.jpg"
                alt="廖壬" />
            
              <p class="site-author-name" itemprop="name">廖壬</p>
              <p class="site-description motion-element" itemprop="description">Learn to choose, to forsake, to endure loneliness, to resist temptation.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">391</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/liaoren512" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:liaoren512@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/5281757990/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="Weibo">
                      
                        <i class="fa fa-fw fa-globe"></i>Weibo</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com" target="_blank" title="Zhihu">
                      
                        <i class="fa fa-fw fa-globe"></i>Zhihu</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-字符串转换"><span class="nav-number">1.</span> <span class="nav-text">1.字符串转换</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-分割字符串"><span class="nav-number">2.</span> <span class="nav-text">2.分割字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-大小写转换"><span class="nav-number">3.</span> <span class="nav-text">3.大小写转换</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-替换null"><span class="nav-number">4.</span> <span class="nav-text">4.替换null</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-执行字符串"><span class="nav-number">5.</span> <span class="nav-text">5.执行字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-拼接字符串"><span class="nav-number">6.</span> <span class="nav-text">6.拼接字符串</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-拼接字符串插入变量"><span class="nav-number">7.</span> <span class="nav-text">7.拼接字符串插入变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-取前-n-行"><span class="nav-number">8.</span> <span class="nav-text">8.取前 n  行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-新建临时表"><span class="nav-number">9.</span> <span class="nav-text">9.新建临时表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-if"><span class="nav-number">10.</span> <span class="nav-text">10.if</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-while"><span class="nav-number">11.</span> <span class="nav-text">11.while</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-for"><span class="nav-number">12.</span> <span class="nav-text">12.for</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#13-向变量赋值"><span class="nav-number">13.</span> <span class="nav-text">13.向变量赋值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#14-从某表新建表并插入数据"><span class="nav-number">14.</span> <span class="nav-text">14.从某表新建表并插入数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#15-赋值"><span class="nav-number">15.</span> <span class="nav-text">15.赋值</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#16-获取传入参数"><span class="nav-number">16.</span> <span class="nav-text">16.获取传入参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#17-执行存储过程"><span class="nav-number">17.</span> <span class="nav-text">17.执行存储过程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#18-定义变量"><span class="nav-number">18.</span> <span class="nav-text">18.定义变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#19-打印语句"><span class="nav-number">19.</span> <span class="nav-text">19.打印语句</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#20-捕获异常"><span class="nav-number">20.</span> <span class="nav-text">20.捕获异常</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#21-查找字符串所在位置"><span class="nav-number">21.</span> <span class="nav-text">21.查找字符串所在位置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#22-delete-join"><span class="nav-number">22.</span> <span class="nav-text">22.delete join</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#23-update-join"><span class="nav-number">23.</span> <span class="nav-text">23.update join</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#24-时间-日期的加减"><span class="nav-number">24.</span> <span class="nav-text">24.时间,日期的加减</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#25-获取日期时间中的一段"><span class="nav-number">25.</span> <span class="nav-text">25.获取日期时间中的一段</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#26-返回当前系统日期时间"><span class="nav-number">26.</span> <span class="nav-text">26.返回当前系统日期时间</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        
<!--<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>-->

<div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">廖壬</span>

  
</div>

<!-- 在网站底部加上访问量-->
<!--<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_pv"></span>
</span>
</div>-->
<!--pv的方式，单个用户连续点击n篇文章，记录n次访问量-->
<!--

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



-->
<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共字</span>
</div>
        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>